package com.lechuang.songbo.view.activity.recyclerView;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.MemoryCategory;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.lechuang.songbo.model.bean.HomeSearchResultBean;
import com.lechuang.songbo.view.activity.home.OnKeyShareCallback;
import com.lechuang.songbo.R;

/**
 * Author: guoning
 * Date: 2017/10/6
 * Description:  赚列表页面的Adapter
 */

public class HomeGetInfoAdapter extends BaseQuickAdapter<HomeSearchResultBean.ProductListBean, GetInfoHolder> {


    private OnKeyShareCallback callback;
    private Context context;

    public HomeGetInfoAdapter(Context context) {
        super(R.layout.item_program_product);
        this.context = context;
    }

    //商品头图片 淘宝或天猫
    private int headImg;

    @Override
    public GetInfoHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return super.onCreateViewHolder(parent, viewType);
    }

    @Override
    protected void convert(final GetInfoHolder helper, final HomeSearchResultBean.ProductListBean listInfo) {
        //商品图
        Glide.with(context).load(listInfo.imgs).into((ImageView) helper.getView(R.id.iv_img));
        //动态调整滑动时的内存占用
        Glide.get(context).setMemoryCategory(MemoryCategory.LOW);
        helper.setText(R.id.tv_oldprice, "原价 ¥" + listInfo.price);
        helper.setText(R.id.tv_name, listInfo.name);
        helper.setText(R.id.tv_nowprice, "券后价 ¥" + listInfo.preferentialPrice);
        if (listInfo.shopType != null && listInfo.shopType.equals("2")) {
            headImg = R.drawable.zhuan_tianmao;
        } else {  //shopType 1淘宝 2天猫 默认淘宝
            headImg = R.drawable.zhuan_taobao;
        }
        Drawable drawable = context.getResources().getDrawable(headImg);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        ((TextView) helper.getView(R.id.tv_name)).setCompoundDrawables(drawable, null, null, null);


       /* SpannelTextView spannelTextView = helper.getView(R.id.spannelTextView);
        spannelTextView.setShopType(Integer.parseInt(listInfo.shopType));
        spannelTextView.setDrawText(listInfo.name);
        Glide.with(context).load(listInfo.img).into((ImageView) helper.getView(R.id.img));
        Glide.get(context).setMemoryCategory(MemoryCategory.LOW);

        helper.setText(R.id.price,String.format("%s", listInfo.price));
        ((TextView)helper.getView(R.id.price)).getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG);
        helper.setText(R.id.preferentialPrice,String.valueOf(listInfo.preferentialPrice));
        helper.setText(R.id.nowNumber,"已售出 "+ listInfo.nowNumber +" 件");
        helper.setText(R.id.couponMoney,String.format(Locale.CHINESE,"%d元", listInfo.couponMoney));
        helper.setText(R.id.zhuanMoney,String.format("赚:%s", listInfo.zhuanMoney));
       SpannelTextView productName =  helper.getView(R.id.spannelTextView);
        productName.setShopType(listInfo.shopType);
        productName.setDrawText(listInfo.productName);
        final ImageView share = helper.getView(R.id.share);

        final int adapterPosition = helper.getAdapterPosition();
        share.setTag(adapterPosition);
//        final HomeCommFragment.InfoHolder tempHolder = holder;
        share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int pos = (Integer) share.getTag();
                if (pos!=adapterPosition)return;
                if (callback!=null)callback.show(listInfo,adapterPosition);
            }
        });*/

    }


    public void setOnKeyShareCallback(OnKeyShareCallback callback) {
        this.callback = callback;
    }

}
